#!/usr/bin/env python3
"""
脚本名称：ch34_exe.py
功能描述： 演示 switch 语句
作者：Gavin
创建日期：2022-05-06
版本：1.0
依赖库：无
使用方法： python ch34_exe.py
"""


def switch(case):
    if case == "A":
        return "Case A"
    elif case == "B":
        return "Case B"
    elif case == "C":
        return "Case C"
    else:
        return "Default case"


result = switch("A")
print(result)  # 输出："Case A"


# 使用字典映射(推荐)
def switch(case):
    switcher = {
        "A": "Case A",
        "B": "Case B",
        "C": "Case C"
    }
    return switcher.get(case, "Default case")


result = switch("B")
print(result)  # 输出："Case B"


# 字典映射，结合函数
def case_a():
    return "Action for case A"


def case_b():
    return "Action for case B"


def case_default():
    return "Default action"


def switch(case):
    switcher = {
        "A": case_a,
        "B": case_b
    }
    func = switcher.get(case, case_default)
    return func()


result = switch("A")
print(result)  # 输出："Action for case A"
